home *** CD-ROM | disk | FTP | other *** search
- #include "UIRoutines.h"
- #include "DialogRoutines.h"
- #include "DesktopSwitch.h"
- #include <Packages.h>
- #include <Events.h>
-
- MenuHandle appleMenu,fileMenu,editMenu;
- Boolean timeToQuit = false;
-
- void ErrorGripe (short errorID)
- {
- SysBeep(1);
- }
-
-
- void WNEDelay (short ticks)
- {
- long startTime;
- EventRecord theEvt;
-
- startTime = TickCount();
-
- do{
- WaitNextEvent (0,&theEvt,ticks,NULL);
- } while (TickCount() - startTime < ticks);
- }
-
- void BuildMenus ()
- {
- appleMenu = GetMenu (kAppleMenu);
- AddResMenu (appleMenu,'DRVR');
- fileMenu = GetMenu (kFileMenu);
- editMenu = GetMenu (kEditMenu);
- InsertMenu (appleMenu,0);
- InsertMenu (fileMenu,0);
- InsertMenu (editMenu,0);
- DrawMenuBar();
- }
-
- void DoAbout ()
- {
- DialogPtr theDlg;
- short theItem;
-
- theDlg = GetNewDialog (130,NULL,(WindowPtr)-1L);
- do {
- ModalDialog ((ProcPtr)StdFilterProc,&theItem);
- } while (theItem != 1);
- DisposeDialog(theDlg);
- }
-
- void DoMenu (long menuCommand) {
- if (HiWord(menuCommand) == kFileMenu) { //if click in the file menu
- switch (LoWord(menuCommand)) {
- case kFile_NewSet:
- CreateDTFileSet();
- break;
- case kFile_LoadSet:
- AskUserForDTFile();
- break;
- case kFile_Prefs:
- ConfigurePrefs();
- break;
- case kFile_HideAll:
- HideItems();
- break;
- case kFile_Quit:
- ExitToShell();
- break;
- }
- }
- if (HiWord(menuCommand) == kAppleMenu) {
- Str31 name;
-
- if (LoWord(menuCommand) == 1)
- DoAbout();
- else {
- GetItem(appleMenu,LoWord(menuCommand),name);
- OpenDeskAcc(name);
- }
-
- }
- }
-
- void HandleMouse(EventRecord theEvent) {
- short wPart;
- long mResult;
- WindowPtr whichWindow;
-
- //the only click we handle is a menu click
- wPart = FindWindow (theEvent.where,&whichWindow);
- if (wPart == inMenuBar) {
- mResult = MenuSelect (theEvent.where);
- if (HiWord(mResult) != 0) {
- DoMenu(mResult);
- HiliteMenu (0);
- }
- }
- }
-
- void mel()
- {
- EventRecord theEvent;
- char theChar;
-
- do{
- WaitNextEvent (everyEvent,&theEvent,5,NULL);
- switch (theEvent.what) {
- case mouseDown:
- HandleMouse(theEvent);
- break;
- case keyDown:case autoKey:
- theChar = (theEvent.message & charCodeMask);
- if (theEvent.modifiers & cmdKey)
- DoMenu(MenuKey(theChar));
- break;
- case kHighLevelEvent:
- AEProcessAppleEvent(&theEvent);
- break;
- }
- } while (!timeToQuit);
- }
-
-
- //based on ThinkRef 2.0 code
- pascal OSErr MyOpenDocuments (AppleEvent *theAppleEvent,
- AppleEvent *reply, long handlerRefcon)
- {
- FSSpec myFSS;
- AEDescList docList;
- OSErr myErr;
- long index, itemsInList;
- Size actualSize;
- AEKeyword keywd;
- DescType returnedType;
-
- myErr = AEGetParamDesc(theAppleEvent, keyDirectObject,
- typeAEList, &docList);
- if (myErr)
- DebugStr("\pError occured retrieving descriptors.");
- // count the number of descriptor records in the list
- myErr = AECountItems (&docList,&itemsInList);
- for (index=1; index<=itemsInList; index++) {
- myErr = AEGetNthPtr(&docList, index, typeFSS, &keywd,
- &returnedType, (Ptr)&myFSS,
- sizeof(myFSS), &actualSize);
- if (myErr)
- DebugStr("\pError occured getting file.");
- LoadDesktopFile(myFSS);
- }
- myErr = AEDisposeDesc(&docList);
- timeToQuit = true;
- return noErr;
- }
-
-
- void InitProg()
- {
- InitGraf (&qd.thePort);
- InitWindows();
- InitFonts ();
- InitDialogs (NULL);
- InitCursor ();
- InitMenus();
- InitAllPacks();
- AEInstallEventHandler (kCoreEventClass,
- kAEOpenDocuments,
- (EventHandlerProcPtr)MyOpenDocuments,
- 0,
- false);
-
- MoreMasters(); MoreMasters(); MoreMasters(); MaxApplZone();
- LoadPrefs();
- BuildMenus();
- }
-
-